<template>
  <div id="previewMain">
    <previewpage ref="previewPagemain" :postData="postData"></previewpage>
  </div>
</template>
<script>
import previewpage from '@/views/index.vue'
import { apiComm } from '@/api/index.js'
export default {
  props: ['fromid'],
  data() {
    return {
      js: '',
      css: '',
      html: '',
      postData: {
        type: 'refreshFrame',
        data: {
          generateConf: {
            fileName: '测试',
            type: 'file'
          },
          html: this.html,
          js: '{}',
          css: this.css,
          scripts: [],
          links: []
        }
      }
    }
  },
  components: { previewpage },
  methods: {
    liulanfrom() {
      if (this.fromid === undefined || this.fromid === null) {
        this.$message.error('表单ID找不到！')
        return false
      }
      apiComm('tappFrom.getFromContent', { fid: fromid }).then(res => {
        const fromcontent = JSON.parse(res.data[0].fromcontent)
        this.js = fromcontent.js
        this.css = fromcontent.css
        this.html = fromcontent.html
        this.postData.data.css = this.css
        this.postData.data.html = this.html
        this.postData.data.js = this.js.replace('export default', '')
        this.$refs.previewPagemain.previewinit(this.postData)
      })
    }
  },
  created() {
    this.liulanfrom()
  }
}
</script>
<style scoped>
#previewMain {
  padding-top: 15px;
  padding-left: 10px;
}
</style>
